package com.example.boos.ui.endOrder;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.RatingBar;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.boos.R;
import com.example.boos.pojo.Comment;


public class commentFragment extends Fragment {
    private Comment comment;
    private CommentCallBack callBack;
    private Menu myMenu;

    private RatingBar riderLevel;
    private EditText riderComment;

    public commentFragment(Comment comment, CommentCallBack callBack){
        this.comment = comment;
        this.callBack = callBack;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.comment_fragment,container,false);
        initData(view);
        return view;
    }

    /*填充数据*/
    private void initData(View view){
        riderLevel = view.findViewById(R.id.riderLevel);
        riderComment = view.findViewById(R.id.add_riderContent);
        riderLevel.setRating(comment.getStoreLevel());
        riderComment.setText(comment.getStoreContent());
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // 在这里监听事件
    }

    // 菜单
    @Override
    public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.back_menu1,menu);
        myMenu = menu;
        for(int i=0;i<menu.size()-1;i++){
            menu.getItem(i).setEnabled(false);
            menu.getItem(i).setVisible(false);
        }
    }
    // 菜单监听事件

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        Log.e("测试","测试菜单");
        // 返回的话其实就是退出这个fragment 然后将隐藏的设置为不隐藏即可
        callBack.back();
        return true;
    }
}
